package com.hykj.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class LoginFilter implements Filter{
	private FilterConfig fc;
	
	public void init(FilterConfig fc) throws ServletException {
		this.setFc(fc);
	}
	public void setFc(FilterConfig fc) {
		this.fc = fc;
	}
	public FilterConfig getFc() {
		return fc;
	}
	public void destroy() {
		this.setFc(null);
	}
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException{
		HttpServletRequest sRequest = (HttpServletRequest)request;
		HttpSession session = sRequest.getSession();
		Object loginer =session.getAttribute("loginer");
		if (loginer == null && !(loginer instanceof com.hykj.valuebean.UserBean)) {
			RequestDispatcher rd = sRequest.getRequestDispatcher("/admin/login.jsp");
			rd.forward(sRequest, response);
		} else {
			chain.doFilter(request, response);
		}
	}

}
